package cn.ee.dfs.esb.controller;

import cn.ee.dfs.common.controller.BaseController;
import cn.ee.dfs.common.entity.DfsConstant;
import cn.ee.dfs.common.utils.DfsUtil;
import cn.ee.dfs.esb.entity.ServiceInfo;
import cn.ee.dfs.esb.service.IServiceInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;


@Slf4j
@Controller("esbView")
public class ViewController extends BaseController {


    @Autowired
    private IServiceInfoService serviceInfoService;


    @GetMapping(DfsConstant.VIEW_PREFIX + "esb/serviceInfo")
    private String serviceInfoIndex() {
        return DfsUtil.view("esb/serviceInfo");
    }

    @GetMapping(DfsConstant.VIEW_PREFIX + "esb/serviceMine")
    private String mineServiceInfoIndex() {
        return DfsUtil.view("esb/serviceMine");
    }

    @GetMapping(DfsConstant.VIEW_PREFIX + "esb/serviceAudit")
    private String serviceAudit() {
        return DfsUtil.view("esb/serviceAudit");
    }


    @GetMapping(DfsConstant.VIEW_PREFIX + "serviceInfo/add")
    @RequiresPermissions("serviceInfo:add")
    public String esbServiceAdd() {
        return DfsUtil.view("esb/serviceAdd");
    }

    @GetMapping(DfsConstant.VIEW_PREFIX + "serviceInfo/detail/{serviceId}")
//    @RequiresPermissions("serviceInfo:add")
    public String esbServiceDetail(@PathVariable("serviceId") String serviceId, Model md) {
        ServiceInfo serviceInfo = serviceInfoService.getById(serviceId);
        log.info("--- serviceInfo -->" + serviceId + serviceInfo);
        md.addAttribute("serviceInfo", serviceInfo);
        return DfsUtil.view("esb/serviceDetail");
    }


    @GetMapping(DfsConstant.VIEW_PREFIX + "serviceInfo/update/{serviceId}")
    @RequiresPermissions("serviceInfo:update")
    public String serviceInfoUpdate(@PathVariable("serviceId") String serviceId, Model md) {

        ServiceInfo serviceInfo = serviceInfoService.getById(serviceId);
        log.info("--- serviceInfo -->{}-{}-" + serviceId + serviceInfo);
        md.addAttribute("serviceInfo", serviceInfo);
        return DfsUtil.view("esb/serviceUpdate");
    }

    @GetMapping(DfsConstant.VIEW_PREFIX + "serviceInfo/addParameter")
//    @RequiresPermissions("esb:parameter:add")
    public String esbServiceParameter() {
        return DfsUtil.view("esb/serviceParameter");
    }

    @GetMapping(DfsConstant.VIEW_PREFIX + "userService/audit/{type}")
//    @RequiresPermissions("esb:parameter:add")
    public String esbServiceAudit(@PathVariable String type) {
        return DfsUtil.view("esb/serviceAuditConsumer");
    }

   @GetMapping(DfsConstant.VIEW_PREFIX + "userService/update/apply")
//    @RequiresPermissions("esb:parameter:add")
    public String esbServiceApplyUpdate() {
        return DfsUtil.view("esb/serviceApply");
    }

}
